//
//  UserInfoParser.m
//  FootPrint
//
//  Created by 秦 东方 on 4/19/13.
//  Copyright (c) 2013 alex tao. All rights reserved.
//

#import "UserInfoParser.h"

@implementation UserInfoParser

- (void)reqUserInfo:(long long)userId{
    
    UserQueryByIdRequestMessage_Builder* builder = [UserQueryByIdRequestMessage builder];
    [builder setUserId:userId];
    [builder setRequestUserId:userId];
    NSData* queryData = [[builder build]data];
    
    if(queryData){
        
        [super noCacheRequestURL:URL_USER_QUERY postData:queryData completion:^(NSData* resultData){
            @try {
                UserQueryByIdResponseMessage* resp = [UserQueryByIdResponseMessage parseFromData:resultData];
                [_delegate didFinishUserInfo:resp];
            }
            @catch (NSException *exception) {
                [_delegate failUser];
            }
            
        } fail:^(NSError * err) {
            [_delegate failUser];
        }];
        
    } else {
        [_delegate failUser];
    }
}


- (void)reqModiInfo:(long long)userId imageId:(long long)imgId nickName:(NSString*)nickName signName:(NSString*)said password:(NSString*)pwd{

    UserProModifyRequestMessage_Builder* builder = [UserProModifyRequestMessage builder];
    [builder setUserId:userId];
    if(imgId > 0){
        [builder setImageId:imgId];
    }
    if(nickName != nil){
        [builder setNickName:nickName];
    }
    if(said != nil){
        [builder setSignName:said];
    }
    if(pwd != nil){
        [builder setPassword:pwd];
    }
    
     NSData* queryData = [[builder build]data];
    if(queryData){
        
        [super noCacheRequestURL:URL_UESR_MIDIFY postData:queryData completion:^(NSData* resultData){
            @try {
                UserProModifyResponseMessage* resp = [UserProModifyResponseMessage parseFromData:resultData];
                [_delegate didFinishModify:resp];
            }
            @catch (NSException *exception) {
                [_delegate failModify];
            }
            
        } fail:^(NSError * err) {
            [_delegate failModify];
        }];
        
    } else {
        [_delegate failModify];
    }
}

@end
